<div class="row">
<div class="col-xs-12">
	<div class="box">
		<div class="box-header">
			<div class="box box-success box-solid">
	            <div class="box-header with-border">
	              <h3 class="box-title">生成规则</h3>
	            </div>
	            <div class="box-body ">
	            	<form id="auto-query-form" class="form-inline" action="generator/build"  method="post" role="form" target="_blank">
					<div class="form-group">
						<label class="control-label" for="prefixes">移除前缀</label>
						<input id="prefixes" name="prefixes" placeholder="表名移除前缀" class="form-control"/>
					</div>
					<div class="form-group">
						<label class="control-label" for="viewPath">子系统目录</label>
						<input id="viewPath" name="viewPath" placeholder="子系统目录" class="form-control"/>
					</div>	
					<div class="form-group">
						<label class="control-label" for="basepackage">Java包</label>
						<input id="basepackage" name="basepackage" placeholder="Java包" class="form-control"/>
						<input id="tables" name="tables" type="hidden"/>
					</div>										
					<div class="form-group">
						<a id="code_submit" class="btn btn-warning" > <i class="fa fa-file-code-o"></i>&nbsp;&nbsp;生成代码</a>
					</div>
					</form>
	            </div>
          </div>
		</div>

		<div class="box-body no-padding">
			<table id="auto_data_table" class="table table-striped table-hover table-bordered no-footer" width="100%">
				<thead>
					<tr>
						<th>
							<div class="checkbox checkbox-warning">
			                    <input id="select_all" type="checkbox">
								<label for="select_all" >&nbsp;</label>
							</div>
						</th>
						<th>表名</th>
						<th>备注</th>
						<th>详情</th>
					</tr>
				</thead>
				<tbody>
					#for(table:result)
					<tr>
						<td></td>
						<td>#(table.name)</td>
						<td>#(table.remarks)</td>
						<td class="text-center"></td>
					</tr>
					#end
				</tbody>
			</table>
		</div>
	</div>
</div>
</div>
<script type="text/javascript">
	$(document).ready(function() {
		var dtSelf = $('#auto_data_table').DataTable({
		      'paging'      : true,
		      'language' : dtLanguageCn,
		      'lengthChange': true,
		      'searching'   : true,
		      'ordering'    : true,
		      'info'        : true,
		      'autoWidth'   : false,
		      'columnDefs': [ {
		            orderable: false,
		            className: 'select-checkbox',
		            width: 40,
		            targets:   0
		        } , {
		            orderable: false,
		            width: 40,
		            targets:   3,
		            render: function(data, type, full) {
						return '<i class="fa fa-plus-square-o row-details"></i>';
					}
		        } ],
		      'select': {
		            style:    'multi',
		            selector: 'td:not(:last)',
		      },
		      order: [[ 1, 'asc' ]],
		      fnInitComplete :function(oSettings, json) {
		          $('#auto_data_table').on('click', ' tbody td .row-details', function () { 
		              var nTr = $(this).parents('tr:first');
		              var tempDt =  $("#auto_data_table").dataTable();
		              if (tempDt.fnIsOpen(nTr)) {
		                  $(this).addClass("fa-plus-square-o").removeClass("fa-minus-square-o");
		                  tempDt.fnClose(nTr);
		              }
		              else {// Open this row
		                  $(this).addClass("fa-minus-square-o").removeClass("fa-plus-square-o");;
		                  tempDt.fnOpen(nTr, function(){
		                	  var row = tempDt.fnGetData(nTr);
		                	  var html = "......";
		                	  $.ajax({url:"generator/detail/"+row[1],dataType:"html",type:"GET",async:false, success:function(data){
		                		  html = data;
		              		  }});
		                	  return html;
		                  }, 'details');
		              }
		          });
		      }
		});
		
		$("#select_all").click(function(){
			if($(this).prop("checked")){
				dtSelf.rows().select();
			}else{
				dtSelf.rows().deselect();
			}
		});
		
		$("#code_submit").click(function(){
			var tables="";
			$("#auto_data_table tr.selected").each(function() {
				var row = dtSelf.row(this).data();
				if(tables!="")tables+=",";
				tables+=row[1];
			});
			if(tables==""){
				showMsg("请选择数据表！","error");
				return;
			}
			if($("#prefixes").val()==""||$("#viewPath").val()==""||$("#basepackage").val()==""){
				showMsg("生成规则不能为空！","error");
				return;
			}
			$("#tables").val(tables);
			$(this).parents("form:first").submit();
		});
	});
</script>